﻿using LuDragon.Common.Enums;
using LuDragon.Data.Entities;
using LuDragon.IService.System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Web;

namespace LuDragon.Service.System
{
    /// <summary>
    /// 日志服务类
    /// </summary>
    public class LogService : BaseService<Sys_Logs>, ILogService
    {
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="actionName">操作名称 </param>
        /// <param name="actionType">操作类型</param>
        /// <param name="user">操作用户</param>
        /// <param name="remark">备注</param>
        public void WriteLog(string actionName, LogMode actionType, Sys_User user, string remark="")
        {
            var model = new Sys_Logs
            {
                ActionName = actionName,
                UserId = user.UserId,
                UserName = user.UserName,
                LogTime = DateTime.Now,
                Remark = remark
            };
            model.ActionType = EnumExtension.GetDisplayDescription(actionType);
            model.LoginIp = HttpContext.Current.Request.UserHostAddress;

            Add(model);
        }
    }
}
